package com.aliothservice.catfish.order.data;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.data.annotation.Id;

public class CompleteVehicleOrder {
	
	public static final String STATUS_UNPAID = "unpaid";
	public final static String STATUS_TRANSPORT_PENDING = "transport_pending";
	public final static String STATUS_TRANSPORT_ONGOING = "transport_ongoing";
	public static final String STATUS_REVIEW_PENDING = "review_pending";
	public static final String STATUS_COMPLETED = "completed";
	public static final String STATUS_CANCELED = "canceled";
	
	public static final String STATUS_APPEAL_ONGOING = "appeal_ongoing";
	
	public Map<String, Object> toMap(String phoneNumberMask) {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("id", this.getId());
		map.put("buyerName", this.getBuyerName());
		map.put("sellerName", this.getSellerName());
		if (null != phoneNumberMask) {
			if (0 == phoneNumberMask.compareTo(this.getBuyerId())) {
				map.put("buyerPhoneNumber", this.getBuyerPhoneNumber());
				if (this.getSellerPhoneNumber().length() != 11) {
					map.put("sellerPhoneNumber", this.getSellerPhoneNumber());
				} else {
					String maskedPhoneNumber = String.format("%s*****%s", this.getSellerPhoneNumber().substring(0, 2), this.getSellerPhoneNumber().substring(7, 10));
					map.put("sellerPhoneNumber", maskedPhoneNumber);
				}
				if (this.getManInChargePhoneNumber().length() != 11) {
					map.put("manInChargePhoneNumber", this.getManInChargePhoneNumber());
				} else {
					String maskedPhoneNumber = String.format("%s*****%s", this.getManInChargePhoneNumber().substring(0, 2), this.getManInChargePhoneNumber().substring(7, 10));
					map.put("manInChargePhoneNumber", maskedPhoneNumber);
				}
			} else {
				map.put("sellerPhoneNumber", this.getSellerPhoneNumber());
				map.put("manInChargePhoneNumber", this.getManInChargePhoneNumber());
				if (this.getBuyerPhoneNumber().length() != 11) {
					map.put("buyerPhoneNumber", this.getBuyerPhoneNumber());
				} else {
					String maskedPhoneNumber = String.format("%s*****%s", this.getBuyerPhoneNumber().substring(0, 2), this.getBuyerPhoneNumber().substring(7, 10));
					map.put("buyerPhoneNumber", maskedPhoneNumber);
				}
			}
		} else {
			map.put("buyerPhoneNumber", this.getBuyerPhoneNumber());
			map.put("sellerPhoneNumber", this.getSellerPhoneNumber());
			map.put("manInChargePhoneNumber", this.getManInChargePhoneNumber());
		}
		map.put("temperatureSpec", this.getTemperatureSpec());
		map.put("originAddress", this.getOriginAddress());
		map.put("destinationAddress", this.getDestinationAddress());
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		map.put("loadingDate", formatter.format(this.getLoadingDate()));
		if (null != this.getBuyerNote()) {
			map.put("buyerNote", this.getBuyerNote());
		}
		map.put("price", this.getPrice());
		map.put("lengthSpec", this.getLengthSpec());
		map.put("fullLoadWeight", this.getFullLoadWeight());
		if (null != this.getFullLoadMass()) {
			map.put("fullLoadMass", this.getFullLoadMass());
		}
		map.put("manInChargeName", this.getManInChargeName());
		map.put("routeOrigin", this.getRouteOrigin());
		map.put("routeDestination", this.getRouteDestination());
		map.put("orderNumber", this.getOrderNumber());
		if (null != this.getAlipayOrderNumber()) {
			map.put("alipayOrderNumber", this.getAlipayOrderNumber());
		}
		DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS");
		map.put("creationDate", fullFormatter.format(this.getCreationDate()));
		map.put("lastUpdateTime", fullFormatter.format(this.getLastUpdateTime()));
		if (null != this.getPaidDate()) {
			map.put("paidDate", fullFormatter.format(this.getPaidDate()));
		}
		if (null != this.getAppealSubmissionDate()) {
			map.put("appealSubmissionDate", fullFormatter.format(this.getAppealSubmissionDate()));
		}
		if (null != this.getVehicle()) {
			map.put("vehicle", this.getVehicle());
		}
		if (null != this.getDriver()) {
			map.put("driver", this.getDriver());
		}
		if (null != this.getBuyerReview()) {
			map.put("buyerReview", this.getBuyerReview());
		}
		if (null != this.getBuyerStarCount()) {
			map.put("buyerStarCount", this.getBuyerStarCount());
		}
		if (null != this.getSellerReview()) {
			map.put("sellerReview", this.getSellerReview());
		}
		if (null != this.getSellerStarCount()) {
			map.put("sellerStarCount", this.getSellerStarCount());
		}
		map.put("status", this.getStatus());
		if (null != this.getDeviceSN()) {
			map.put("deviceSN", this.getDeviceSN());
		}
		if (null != this.getRefundAmount()) {
			map.put("refundAmount", this.getRefundAmount());
		}
		if (null != this.getAppealDescription()) {
			map.put("appealDescription", this.getAppealDescription());
		}
		if (null != this.getServiceId()) {
			map.put("serviceId", this.getServiceId());
		}
		
		return map;
	}

	@Id
	private String id;
	private String serviceId;
	
	// contact info
	private String buyerId;
	private String sellerId;	
	private String buyerName;
	private String buyerPhoneNumber;
	private String sellerName;
	private String sellerPhoneNumber;
	
	// order info	
	private String temperatureSpec;	
	private String originAddress;
	private String destinationAddress;
	private Date loadingDate;
	private String buyerNote;
	
	// service info
	private Float price;
	private String lengthSpec;
	private Integer fullLoadWeight;
	private Integer fullLoadMass;
	private String manInChargeName;
	private String manInChargePhoneNumber;
	private String routeOrigin;
	private String routeDestination;
	
	private String orderNumber;
	private String alipayOrderNumber;
	
	private String buyerReview;
	private Integer buyerStarCount;
	private String sellerReview;
	private Integer sellerStarCount;
	
	private Map<String, Object> vehicle;
	private Map<String, Object> driver;
	
	private String status;
	
	private LocalDateTime creationDate;
	private LocalDateTime paidDate;
	private LocalDateTime lastUpdateTime;
	
	private String deviceSN;
	
	private LocalDateTime appealSubmissionDate;
	private Integer refundAmount;
	private String appealDescription;
	
	private String paymentUrl;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getBuyerId() {
		return buyerId;
	}

	public void setBuyerId(String buyerId) {
		this.buyerId = buyerId;
	}

	public String getSellerId() {
		return sellerId;
	}

	public void setSellerId(String sellerId) {
		this.sellerId = sellerId;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getBuyerName() {
		return buyerName;
	}

	public void setBuyerName(String buyerName) {
		this.buyerName = buyerName;
	}

	public String getBuyerPhoneNumber() {
		return buyerPhoneNumber;
	}

	public void setBuyerPhoneNumber(String buyerPhoneNumber) {
		this.buyerPhoneNumber = buyerPhoneNumber;
	}

	public String getTemperatureSpec() {
		return temperatureSpec;
	}

	public void setTemperatureSpec(String temperatureSpec) {
		this.temperatureSpec = temperatureSpec;
	}

	public String getOriginAddress() {
		return originAddress;
	}

	public void setOriginAddress(String originAddress) {
		this.originAddress = originAddress;
	}

	public String getDestinationAddress() {
		return destinationAddress;
	}

	public void setDestinationAddress(String destinationAddress) {
		this.destinationAddress = destinationAddress;
	}

	public String getBuyerNote() {
		return buyerNote;
	}

	public void setBuyerNote(String buyerNote) {
		this.buyerNote = buyerNote;
	}

	public String getSellerName() {
		return sellerName;
	}

	public void setSellerName(String sellerName) {
		this.sellerName = sellerName;
	}

	public String getSellerPhoneNumber() {
		return sellerPhoneNumber;
	}

	public void setSellerPhoneNumber(String sellerPhoneNumber) {
		this.sellerPhoneNumber = sellerPhoneNumber;
	}

	public LocalDateTime getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(LocalDateTime creationDate) {
		this.creationDate = creationDate;
	}

	public LocalDateTime getLastUpdateTime() {
		return lastUpdateTime;
	}

	public void setLastUpdateTime(LocalDateTime lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}

	public String getLengthSpec() {
		return lengthSpec;
	}

	public void setLengthSpec(String lengthSpec) {
		this.lengthSpec = lengthSpec;
	}

	public Integer getFullLoadWeight() {
		return fullLoadWeight;
	}

	public void setFullLoadWeight(Integer fullLoadWeight) {
		this.fullLoadWeight = fullLoadWeight;
	}

	public String getManInChargeName() {
		return manInChargeName;
	}

	public void setManInChargeName(String manInChargeName) {
		this.manInChargeName = manInChargeName;
	}

	public String getManInChargePhoneNumber() {
		return manInChargePhoneNumber;
	}

	public void setManInChargePhoneNumber(String manInChargePhoneNumber) {
		this.manInChargePhoneNumber = manInChargePhoneNumber;
	}

	public String getRouteOrigin() {
		return routeOrigin;
	}

	public void setRouteOrigin(String routeOrigin) {
		this.routeOrigin = routeOrigin;
	}

	public String getRouteDestination() {
		return routeDestination;
	}

	public void setRouteDestination(String routeDestination) {
		this.routeDestination = routeDestination;
	}

	public Float getPrice() {
		return price;
	}

	public void setPrice(Float price) {
		this.price = price;
	}

	public Date getLoadingDate() {
		return loadingDate;
	}

	public void setLoadingDate(Date loadingDate) {
		this.loadingDate = loadingDate;
	}

	public String getOrderNumber() {
		return orderNumber;
	}

	public void setOrderNumber(String orderNumber) {
		this.orderNumber = orderNumber;
	}

	public Map<String, Object> getVehicle() {
		return vehicle;
	}

	public void setVehicle(Map<String, Object> vehicle) {
		this.vehicle = vehicle;
	}

	public Map<String, Object> getDriver() {
		return driver;
	}

	public void setDriver(Map<String, Object> driver) {
		this.driver = driver;
	}

	public String getBuyerReview() {
		return buyerReview;
	}

	public void setBuyerReview(String buyerReview) {
		this.buyerReview = buyerReview;
	}

	public Integer getBuyerStarCount() {
		return buyerStarCount;
	}

	public void setBuyerStarCount(Integer buyerStarCount) {
		this.buyerStarCount = buyerStarCount;
	}

	public String getSellerReview() {
		return sellerReview;
	}

	public void setSellerReview(String sellerReview) {
		this.sellerReview = sellerReview;
	}

	public Integer getSellerStarCount() {
		return sellerStarCount;
	}

	public void setSellerStarCount(Integer sellerStarCount) {
		this.sellerStarCount = sellerStarCount;
	}

	public LocalDateTime getPaidDate() {
		return paidDate;
	}

	public void setPaidDate(LocalDateTime paidDate) {
		this.paidDate = paidDate;
	}

	public String getAlipayOrderNumber() {
		return alipayOrderNumber;
	}

	public void setAlipayOrderNumber(String alipayOrderNumber) {
		this.alipayOrderNumber = alipayOrderNumber;
	}

	public String getDeviceSN() {
		return deviceSN;
	}

	public void setDeviceSN(String deviceSN) {
		this.deviceSN = deviceSN;
	}

	public LocalDateTime getAppealSubmissionDate() {
		return appealSubmissionDate;
	}

	public void setAppealSubmissionDate(LocalDateTime appealSubmissionDate) {
		this.appealSubmissionDate = appealSubmissionDate;
	}

	public String getAppealDescription() {
		return appealDescription;
	}

	public void setAppealDescription(String appealDescription) {
		this.appealDescription = appealDescription;
	}

	public Integer getRefundAmount() {
		return refundAmount;
	}

	public void setRefundAmount(Integer refundAmount) {
		this.refundAmount = refundAmount;
	}

	public String getServiceId() {
		return serviceId;
	}

	public void setServiceId(String serviceId) {
		this.serviceId = serviceId;
	}

	public Integer getFullLoadMass() {
		return fullLoadMass;
	}

	public void setFullLoadMass(Integer fullLoadMass) {
		this.fullLoadMass = fullLoadMass;
	}

	public String getPaymentUrl() {
		return paymentUrl;
	}

	public void setPaymentUrl(String paymentUrl) {
		this.paymentUrl = paymentUrl;
	}
	
}
